<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%user_company}}".
 *
 * @property integer $id
 * @property integer $user_id
 * @property integer $type
 * @property string $name
 * @property string $url
 * @property string $telphone
 * @property string $fax
 * @property string $product
 * @property integer $category_id
 * @property string $category
 * @property string $contact_user
 * @property string $contact_mobile
 * @property string $business
 * @property string $business_photo
 * @property string $origanization_code_photo
 * @property string $certificate_photo
 * @property string $opening_permit_photo
 * @property integer $status
 * @property string $reason
 * @property integer $version
 * @property string $created_by
 * @property integer $created_at
 * @property string $created_from
 * @property string $created_ip
 * @property string $updated_by
 * @property integer $updated_at
 * @property string $updated_from
 * @property string $updated_ip
 * @property integer $is_deleted
 *
 * @property User $user
 */
class UserCompany extends \common\base\BaseActiveRecord
{

    const COMPANY_TYPE_NORMAL = 0;//普通用户
    const COMPANY_TYPE_Z = 1;//主办方
    const COMPANY_TYPE_C = 2;//参展商
    const COMPANY_TYPE_F = 3;//服务商

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%user_company}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id'], 'required'],
            [['user_id', 'category_id', 'type', 'status', 'version', 'created_at', 'updated_at', 'is_deleted'], 'integer'],
            [['name', 'product', 'category', 'business_photo', 'origanization_code_photo', 'certificate_photo', 'opening_permit_photo', 'reason'], 'string', 'max' => 200],
            [['url'], 'string', 'max' => 255],
            [['telphone', 'fax', 'business'], 'string', 'max' => 30],
            [['contact_user'], 'string', 'max' => 100],
            [['contact_mobile'], 'string', 'max' => 11],
            [['created_by', 'created_from', 'created_ip', 'updated_by', 'updated_from', 'updated_ip'], 'string', 'max' => 50],
            //['status', 'default', 'value' => self::STATUS_FLAG_NORMAL],
            //['status', 'in', 'range' => [self::STATUS_FLAG_TEMP, self::STATUS_FLAG_NORMAL, self::STATUS_FLAG_STOP]],
            [['contact_mobile'], 'match', 'pattern' => '/^1\d{10}$/', 'message' => '指定联系人手机号格式错误'],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('common', 'id'),
            'user_id' => Yii::t('common', 'user_id'),
            'type' => Yii::t('common', 'type'),
            'name' => Yii::t('common', 'name'),
            'url' => Yii::t('common', 'url'),
            'telphone' => Yii::t('common', 'telphone'),
            'fax' => Yii::t('common', 'fax'),
            'product' => Yii::t('common', 'product'),
            'category_id' => Yii::t('common', 'category_id'),
            'category' => Yii::t('common', 'category'),
            'contact_user' => Yii::t('common', 'contact_user'),
            'contact_mobile' => Yii::t('common', 'contact_mobile'),
            'business' => Yii::t('common', 'business'),
            'business_photo' => Yii::t('common', 'business_photo'),
            'origanization_code_photo' => Yii::t('common', 'origanization_code_photo'),
            'certificate_photo' => Yii::t('common', 'certificate_photo'),
            'opening_permit_photo' => Yii::t('common', 'opening_permit_photo'),
            'status' => Yii::t('common', 'status'),
            'reason' => Yii::t('common', 'reason'),
            'version' => Yii::t('common', 'version'),
            'created_by' => Yii::t('common', 'created_by'),
            'created_at' => Yii::t('common', 'created_at'),
            'created_from' => Yii::t('common', 'created_from'),
            'created_ip' => Yii::t('common', 'created_ip'),
            'updated_by' => Yii::t('common', 'updated_by'),
            'updated_at' => Yii::t('common', 'updated_at'),
            'updated_from' => Yii::t('common', 'updated_from'),
            'updated_ip' => Yii::t('common', 'updated_ip'),
            'is_deleted' => Yii::t('common', 'is_deleted'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), ['id' => 'user_id']);
    }
}
